﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台主界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/reset.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/admin.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/daily_record.css' type="text/css" />
<script src="<?php echo $static_url; ?>common/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/common.js" type="text/javascript"></script>
</head>
<body class="body_background">
	<div>
		<?php echo $header_nav; ?>
		
		<div class="common_container clearfix">
			<div class="crumbs">
				<span class="catalogue">栏目管理</span>
				<a title="栏目列表" href="/www/admin/news/category/category_lists.php">栏目列表</a> |
				<a href="/www/admin/news/category/category_add.php" title="添加一级栏目">添加一级栏目</a> |
				<a href="/www/admin/news/category/category_recover.php">回收站</a>
			</div>
			<div class="daily_record_menu" id="side_container">
				<div class="closeSidebar"><i title="点击隐藏左菜单" class="icon_close"></i></div>
				<ul class="record_menu">
					<li style="font-size:14px;">栏目管理</li>
					<li><a href="/www/admin/news/category/category_lists.php"> └ 栏目列表</a></li>
					<li><a href="/www/admin/news/category/category_add.php"> └ 添加一级栏目</a></li>
					<li><a href="/www/admin/news/category/category_recover.php"> └ 回收站</a></li>
				</ul>
			</div>
			<div class="sidebar_container_hidden" style="margin-top:10px;margin-right:5px;" >
				<div class="openSidebar"><i title="点击显示左菜单" class="icon_open"></i></div>
			</div>
			<div class="daily_record_main" id="main_container">
				<div>
					<table class="record_tips"><tr><td>栏目列表</td></tr></table>
						<div class="block-body collapse in" id="page-stats">
						<table class="programa_table" width="100%">
							<thead>
								<tr>
									<th width="86">是否展开</th>
									<th width="52">ID</th>
									<th width="150">显示顺序</th>
									<th>栏目标题</th>
									<th width="110">操作</th>
								</tr>
							</thead>
							<tbody>
							<?php
								foreach($category_rs as $category_rss):
							?>
							
								<tr>
									<td width="86" class="text_align_center" id="category_<?php echo $category_rss['id']; ?>">
							<?php 
										if(!empty($category_rss['child_id'])){
											echo '<a href="javascript:;" onclick="get_category(1,'.$category_rss['id'].',1)">[+]</a>';
										}else{
											echo '&nbsp;';
										}
							?>
									</td>
									<td width="50" class="td_text_center"><?php echo $category_rss['id']; ?></td>
									<td width="150" class="td_text_center"><?php echo $category_rss['orders']; ?></td>
									<td class="column_title"><?php echo $category_rss['title']; ?></td>
									<td width="150" class="td_text_center">
										<a href="/www/admin/news/category/category_add.php?parent_id=<?php echo $category_rss['id']; ?>&amp;top_id=0">新增</a>
										<a href="/www/admin/news/category/category_edit.php?id=<?php echo $category_rss['id']; ?>">编辑</a>
										<a href="javascript:del_category(<?php echo $category_rss['id']; ?>);" onclick="return confirm('确定删除《<?php echo $category_rss['title']; ?>》栏目吗？')">删除</a>
									</td>
								</tr>
							<?php
								if(!empty($category_rss['child_id'])){
									echo '<tr id ="category_toggle_'.$category_rss['id'].'" style="display:none;" ><td colspan="5"><table class="secondCategory category_'.$category_rss['id'].'" width="100%"></table></td></tr>';
								}
							endforeach;
							?>
						</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
<script>
	//删除栏目
	function del_category(i){<!-- i:id号 -->
		$.ajax({
			type: "POST",
			url: "/admin/news/category/ajax/ajax_del.php",
			dataType:'json',
			data: {"id":i},
			success: function(msg){
				alert(msg.string);
				if(msg.error){
					window.location.href="/www/admin/news/category/category_lists.php";
				}
			}
		});
	}
	
	//获取当前栏目的所有子栏目并回显
	function get_category(m,i,k){<!-- m:显示或隐藏，i:id号，k:第几层 -->
		var $category_id = $("#category_"+i);
		var $category_class = $(".category_"+i);
		var $category_toggle = $("#category_toggle_"+i);
		if( m == 1 ){
			if( $category_class.html() == '' ){
				$.ajax({
					type: "POST",
					url: "/admin/news/category/ajax/ajax_lists.php",
					data: {"id":i,"k":k},
					dataType: 'html',
					success: function(data){
						$category_class.html(data);
					}
				});
			}
			$category_id.html("<a href='javascript:;' onclick='get_category(0,"+i+","+k+")'>[-]</a>");
			$category_toggle.show();
		}else{
			$category_id.html("<a href='javascript:;' onclick='get_category(1,"+i+","+k+")'>[+]</a>");
			$category_toggle.hide();
		}
	}
</script>
</body>
</html>